package com.rljk.service.impl;

import com.github.pagehelper.PageHelper;
import com.rljk.common.dao.DaoSupport;
import com.rljk.domain.common.PageData;
import com.rljk.redis.RedisService;
import com.rljk.service.UserManager;
import com.rljk.utils.QrCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/** 
 * 说明： 用户表
 * 创建人：zhaozhenhua
 * 创建时间：2018-06-27
 * @version
 */
@Service("userService")
public class UserService implements UserManager {

	@Resource(name = "daoSupport")
	private DaoSupport dao;

	@Autowired
	RedisService redisService;
	
	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public void save(PageData pd)throws Exception{
		dao.save("UserMapper.save", pd);
	}
	
	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void delete(PageData pd)throws Exception{
		dao.delete("UserMapper.delete", pd);
	}
	
	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		dao.update("UserMapper.edit", pd);
	}
	
	/**分页列表
	 * @param currentPage
	 * @param pageSize
	 * @param pd
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<PageData> listPage(int currentPage,int pageSize,PageData pd)throws Exception{
	    PageHelper.startPage(currentPage,pageSize);
		return (List<PageData>)dao.findForList("UserMapper.listAll", pd);
	}


    /**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<PageData> listAll(PageData pd)throws Exception{
		return (List<PageData>)dao.findForList("UserMapper.listAll", pd);
	}
	
	/**通过id获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findById(PageData pd)throws Exception{
		return (PageData)dao.findForObject("UserMapper.findById", pd);
	}

	/**通过用户名或者密码获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findByNameOrPassword(PageData pd) throws Exception {
		return (PageData)dao.findForObject("UserMapper.findByNameOrPassword", pd);
	}

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		dao.delete("UserMapper.deleteAll", ArrayDATA_IDS);
	}

	/**
	 *更新用户经纬度接口
	 */
	@Override
	@Transactional
	public void updLocation(PageData pd) throws Exception {
		String token = redisService.get("TOKEN");



	}

	/**
	 * 获取所有用户的id
	 */
	@Override
	public List<String> getAllUserId() throws Exception {
		return (List<String>)dao.findForList("UserMapper.getAllUserId",null);
	}

	/**
	 * 通过PHONE获取数据
	 */
	@Override
	public PageData findByPhone(PageData pd) throws Exception {
		return (PageData) dao.findForObject("UserMapper.findByPhone", pd);
	}

	/**
	 * 获取用户的二维码邀请码和次数
	 */
	@Override
	public PageData getQRcodeAndNumber(String userId) throws Exception {
		return (PageData)dao.findForObject("UserMapper.getQRcodeAndNumber", userId);
	}

}

